// packageJ/coffee_machine/coffee_machine_record/coffee_machine_record.js
const app = getApp();
import util from "../../../utils/util";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    value1: false,
    value2: false,
    option1: [{
        text: "角色类型",
        value: 0
      },
      {
        text: "机主",
        value: 1
      },
      {
        text: "运维",
        value: 2
      }
    ],
    option2: [{
        text: "结算状态",
        value: 0
      },
      {
        text: "已结算",
        value: 1
      },
      {
        text: "结算中",
        value: 2
      },
      {
        text: "未结算",
        value: 3
      },
      {
        text: "全部",
        value: 4
      }
    ],
    isNowDay: "",
    dayShow: false,
    currentDate: new Date().getTime(),
    maxDate: new Date().getTime(),
    day: "",
    role_id: "",
    statusL: "",
    listInfo: [],

    isLoadMore: true,
    page: 1,
    total_page: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.setNavigationBarTitle({
      title: '收入明细',
    })
    this.data.options = options;
    this.getSelect();
  },
  checkPopover() {
    if (this.data.value1 || this.data.value2) {
      console.log('dasdasd')
      this.setData({
        value1: false,
        value2: false
      })
    }
  },
  chooseChildOne2(e) {
    this.setData({
      value2: false,
      statusL: e.detail.status,
    })
    console.log(this.data.statusL,'statusL')
    this.getData();
  },
  chooseChildOne(e) {
    this.setData({
      value1: false,
      role_id: e.detail.id,
    })
    console.log(this.data.role_id,'role_id')
    this.getData();
  },
  dayShowTap() {
    this.setData({
      dayShow: true
    })
  },
  dayShowConfirm(e) {
    let res = wx.getSystemInfoSync();
    let {
      detail
    } = e;
    let value = new Date(detail);
    let isNow;
    if (res.platform == 'ios') {
      isNow = util.formatTime(value);
    } else {
      isNow = util.formatTimes(value);
    }
    this.setData({
      isNowDay: isNow,
      dayShow: false
    })
    this.getData();
  },
  closeMethods() {
    this.setData({
      dayShow: false
    })
  },
  taValue1(e) {
    this.setData({
      value1: !this.data.value1,
      value2: false
    })
  },
  taValue2(e) {
    this.setData({
      value2: !this.data.value2,
      value1: false
    })
    this.getData();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  getSelect() {
    let urlStr = app.getNetAddresss("plugin.coffee-machine.frontend.owner.getSelect");
    app._postNetWork({
      url: urlStr,
      data: {
        machine_id: this.data.options.machine_id,
      },
      success: (resdata) => {
        let res = resdata.data
        if (res.result == 1) {
          this.setData({
            option1: res.data.role_list,
            option2: res.data.commission_status
          })
          console.log(this.data.option1, this.data.option2)
        } else {
          app.tips(res.msg)
        }
      },
      fail: function (res) {}
    });
  },
  getData() {
    let json = {
      machine_id: this.data.options.machine_id,
      day: this.data.isNowDay,
      role_id: this.data.role_id ? this.data.role_id : "",
      status: this.data.statusL
    };
    let urlStr = app.getNetAddresss("plugin.coffee-machine.frontend.owner.incomeList");
    app._postNetWork({
      url: urlStr,
      data: json,
      success: (resdata) => {
        let res = resdata.data
        if (res.result == 1) {
          this.setData({
            listInfo: res.data.data
          })
          this.data.isLoadMore = true;
          this.data.total_page = res.data.last_page;
          if (!this.data.total_page) {
            this.data.total_page = 0;
          }
        } else {
          app.tips(res.msg)
        }
      },
      fail: function (res) {}
    });
  }
})